home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / 8Bawl.bproj / 8Bawl(2).class < prev    next >
Encoding:
Text File  |  1994-05-23  |  7.2 KB  |  210 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //    FILENAME:    8Bawl.m
  3. //    SUMMARY:    an Eight-Ball (TM) Annotation
  4. //    SUPERCLASS:    Object
  5. //    INTERFACE:    None
  6. //    PROTOCOLS:    <Annotation, Tool>
  7. //    AUTHOR:        Eric P. Scott, ported to eText by Rohit Khare
  8. //    COPYRIGHT:    (c) 1994 California Institure of Technology, eText Project
  9. //    COPYRIGHT:    (c) 1994 San Francisco State University
  10. ///////////////////////////////////////////////////////////////////////////////
  11. //    DESCRIPTION
  12. //        An example of how to port over a simple View-based widget. Original
  13. //    application and 8Bawl source code by Eric P. Scott, Tech alum @ SFSU
  14. ///////////////////////////////////////////////////////////////////////////////
  15. //             BawlApp.m: a toy for the virtual desktop
  16. //             Eric P. Scott, San Francisco State University, January 1994
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //    HISTORY
  19. //    05/22/94:    Created. First eText port.
  20. ///////////////////////////////////////////////////////////////////////////////
  21.  
  22. #import "../eTextKernel.h"
  23. #include "wraps8.h"
  24. #include <bsd/libc.h>
  25.  
  26. #define    NIMAGES 21
  27. @class EBI;
  28.  
  29. // File-Scope Global shared by all 8Bawls
  30. id    face[NIMAGES];
  31. id    base8;
  32. id    big8;
  33. BOOL initted=NO;
  34.  
  35.  
  36. @interface EightBawl:Object <Annotation, Tool>
  37. {    BOOL    highlighted;
  38. }
  39. @end
  40.  
  41. @implementation EightBawl
  42.  
  43. const NXRect bigRect={ { 0.0, 0.0 }, { 288.0, 288.0 } };
  44. const NXPoint smallRectOrigin={ 96.0, 88.0}, smallRectUpOrigin={ 96.0, 116.0};
  45. const NXSize smallRectSize={ 96.0, 84.0};
  46.  
  47. + toolAwake:theApp
  48. {
  49.     long         now;
  50.     int         i;
  51.     char        buf[MAXPATHLEN];
  52.     NXBundle    *bundle;
  53.     
  54.     (void)time(&now);
  55.     srandom((int)now^(0xffffff));
  56.     if (!initted) {
  57.     for(i=0; i < NIMAGES; i++) face[i] = nil;
  58.     bundle = [NXBundle bundleForClass:[EightBawl class]];
  59.     if ([bundle getPath:buf forResource:"Base8" ofType:"eps"] )
  60.         base8 = [[NXImage alloc] initFromFile:buf];
  61.     if ([bundle getPath:buf forResource:"Big8" ofType:"eps"] )
  62.         big8 = [[NXImage alloc] initFromFile:buf];
  63.     if ([bundle getPath:buf forResource:"small8" ofType:"tiff"] )
  64.         face[0] = [[NXImage alloc] initFromFile:buf];
  65.     if ([bundle getPath:buf forResource:"ask_again" ofType:"tiff"] )
  66.         face[1] = [[NXImage alloc] initFromFile:buf];
  67.     if ([bundle getPath:buf forResource:"as_i_see_it" ofType:"tiff"] )
  68.         face[2] = [[NXImage alloc] initFromFile:buf];
  69.     if ([bundle getPath:buf forResource:"better_not" ofType:"tiff"] )
  70.         face[3] = [[NXImage alloc] initFromFile:buf];
  71.     if ([bundle getPath:buf forResource:"certain" ofType:"tiff"] )
  72.         face[4] = [[NXImage alloc] initFromFile:buf];
  73.     if ([bundle getPath:buf forResource:"cannot_predict" ofType:"tiff"] )
  74.         face[5] = [[NXImage alloc] initFromFile:buf];
  75.     if ([bundle getPath:buf forResource:"concentrate" ofType:"tiff"] )
  76.         face[6] = [[NXImage alloc] initFromFile:buf];
  77.     if ([bundle getPath:buf forResource:"decidedly" ofType:"tiff"] )
  78.         face[7] = [[NXImage alloc] initFromFile:buf];
  79.     if ([bundle getPath:buf forResource:"may_rely" ofType:"tiff"] )
  80.         face[8] = [[NXImage alloc] initFromFile:buf];
  81.     if ([bundle getPath:buf forResource:"outlook_good" ofType:"tiff"] )
  82.         face[9] = [[NXImage alloc] initFromFile:buf];
  83.     if ([bundle getPath:buf forResource:"definitely" ofType:"tiff"] )
  84.         face[10] = [[NXImage alloc] initFromFile:buf];
  85.     if ([bundle getPath:buf forResource:"outlook_not" ofType:"tiff"] )
  86.         face[11] = [[NXImage alloc] initFromFile:buf];
  87.     if ([bundle getPath:buf forResource:"reply_hazy" ofType:"tiff"] )
  88.         face[12] = [[NXImage alloc] initFromFile:buf];
  89.     if ([bundle getPath:buf forResource:"dont_count" ofType:"tiff"] )
  90.         face[13] = [[NXImage alloc] initFromFile:buf];
  91.     if ([bundle getPath:buf forResource:"reply_no" ofType:"tiff"] )
  92.         face[14] = [[NXImage alloc] initFromFile:buf];
  93.     if ([bundle getPath:buf forResource:"signs_point" ofType:"tiff"] )
  94.         face[15] = [[NXImage alloc] initFromFile:buf];
  95.     if ([bundle getPath:buf forResource:"doubtful" ofType:"tiff"] )
  96.         face[16] = [[NXImage alloc] initFromFile:buf];
  97.     if ([bundle getPath:buf forResource:"sources_say" ofType:"tiff"] )
  98.         face[17] = [[NXImage alloc] initFromFile:buf];
  99.     if ([bundle getPath:buf forResource:"without_doubt" ofType:"tiff"] )
  100.         face[18] = [[NXImage alloc] initFromFile:buf];
  101.     if ([bundle getPath:buf forResource:"most_likely" ofType:"tiff"] )
  102.         face[19] = [[NXImage alloc] initFromFile:buf];
  103.     if ([bundle getPath:buf forResource:"yes" ofType:"tiff"] )
  104.         face[20] = [[NXImage alloc] initFromFile:buf];
  105.     initted = YES;
  106.     }
  107.     [theApp   registerAnnotation: [EightBawl class] 
  108.                             name: "EightBawl"
  109.                     RTFDirective: "EightBawl"
  110.                        menuLabel: "Consult 8Bawl..."
  111.                          menuKey: '\0'
  112.                         menuIcon: (NXImage *) face[0]];
  113.     return self;
  114. }
  115.  
  116. - init
  117. {
  118.     return self;
  119. }
  120.  
  121. - free
  122. {
  123.     [[NXApp inspector] invalidate];
  124.     return [super free];
  125. }
  126.  
  127. - initFromPboard:thePB inDoc:theDoc linked:(BOOL) linked {return [self init];}
  128.  
  129. // drawing loops -- trackMouse
  130. - (BOOL)    trackMouse:(NXEvent *)event
  131.             inRect:(const NXRect *)cellFrame
  132.             ofView:controlView    
  133. {
  134.     const NXPoint zero={ 0.0, 0.0 };
  135.     NXRect cr;
  136.     NXPoint    point;
  137.     int k;
  138.     float dpt;
  139.     static id cimage=nil;
  140.  
  141.     [[NXApp inspector] inspect:[EBI new]];    
  142.     PSgsave();
  143.     PSobscurecursor();
  144.     PSsetwaitcursorenabled(NO);    // cheating!
  145.     if (highlighted) PSsetgray(NX_LTGRAY);
  146.     else PSsetgray([controlView backgroundGray]);
  147.     NXRectFill(cellFrame);
  148.     PSgrestore();
  149.     point = cellFrame->origin;
  150.     point.y += cellFrame->size.height;
  151.     [base8 composite:NX_SOVER toPoint:&point];
  152.     point.x += smallRectOrigin.x;
  153.     k = (int)(random()&0x7fffffff)%(NIMAGES-1) + 1;
  154.     if ((k-1)%3 == 0) point.y -= smallRectUpOrigin.y;
  155.     else point.y -= smallRectOrigin.y;
  156. //    dissolve base8 up to face[k]    
  157.     if (!cimage) cimage=[[NXImage alloc] initSize:&smallRectSize];
  158.     [cimage setUnique:YES];    // this image must stay opaque!
  159.     [cimage setBackgroundColor:NX_COLORWHITE];
  160.     [cimage useCacheWithDepth:NX_DefaultDepth];
  161.     [cimage lockFocus];
  162.     cr.size = smallRectSize;
  163.     cr.origin=((k-1)%3 == 0) ? smallRectUpOrigin : smallRectOrigin;
  164.     [base8 composite:NX_SOVER fromRect:&cr toPoint:&zero];
  165.     [face[k] composite:NX_SOVER toPoint:&zero];
  166.     [cimage unlockFocus];
  167. //    for (dpt = 0.1; dpt < 1.0; dpt += .1){
  168. //        [cimage dissolve:dpt toPoint:&point];
  169. //        DPSFlush();
  170. //        [[controlView window] flushWindow];
  171. //        NXPing();
  172. //    }
  173. //    dissolve face[k] down to big8
  174.     PSgsave();
  175. //    PSsetgray([controlView backgroundGray]);
  176. //    NXRectFill(cellFrame);
  177. //    point = cellFrame->origin;
  178. //  point.y += cellFrame->size.height;
  179. //    [big8 composite:NX_SOVER toPoint:&point]; 
  180.     [cimage composite:NX_SOVER toPoint:&point];
  181.     PSgrestore();
  182.     PSsetwaitcursorenabled(YES);
  183.     return YES;
  184. }
  185. // default drawSelf
  186. - drawSelf:(const NXRect *)cellFrame inView:view        // MARGINALIA HERE!
  187. {
  188.     NXPoint    point;
  189.     
  190.     PSgsave();
  191.     if (highlighted) PSsetgray(NX_LTGRAY);
  192.     else PSsetgray([view backgroundGray]);
  193.     NXRectFill(cellFrame);
  194.     
  195.     point = cellFrame->origin;
  196.     point.y += cellFrame->size.height;
  197.     [big8 composite:NX_SOVER toPoint:&point];
  198.     PSgrestore();
  199.     return self;
  200. }
  201.  
  202. - calcCellSize:(NXSize *)theSize 
  203.     {theSize->width = theSize->height = 288.0; return self;}
  204. - highlight:(const NXRect *)rect inView:view lit:(BOOL)flag
  205.     {highlighted = !highlighted; NXHighlightRect(rect);return self;}
  206. - readRichText:(NXStream *)stream forView:view 
  207.     {return self;}
  208. - writeRichText:(NXStream *)stream forView:view
  209.     {return self;}
  210. @end